using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Crm.Domain.TestUtil;
using TestUtil.Equality;

namespace Crm.Domain.Tests
{
    [TestFixture]
    public class CustomerTests
    {
        #region Tests

        [Test]
        public void MustProvideCustomerIdentifier()
        {
            CustomerIdentifier identifier = new CustomerIdentifier(CustomerCommonTestValues.CustomerIdentifierString);

            Customer customer = new Customer(identifier);

            Assert.AreEqual(identifier, customer.Identifier, "Customer identifier not correctly set.");
        }

        # endregion

        # region Tests - Equality

        [Test]
        public void EqualityTest()
        {
            CreateTestObjectCallback<Customer> firstCallback =
                delegate { return CreateCustomer(CustomerCommonTestValues.CustomerIdentifierString); };
            CreateTestObjectCallback<Customer> secondCallback =
                delegate { return CreateCustomer(CustomerCommonTestValues.SecondCustomerIdentifierString); };

            ReferenceTypeValueObjectEqualityTestHelper<Customer> helper =
                new ReferenceTypeValueObjectEqualityTestHelper<Customer>(firstCallback, secondCallback);
        }

        [Test]
        public void TwoCustomersEqualIfHaveSameIdentifier()
        {
            Customer firstCustomer = CreateCustomer(CustomerCommonTestValues.CustomerIdentifierString);
            Customer secondCustomer = CreateCustomer(CustomerCommonTestValues.CustomerIdentifierString);

            Assert.AreEqual(firstCustomer, secondCustomer, "Two Customers with the same identifier should be equal.");
        }

        [Test]
        public void TwoCustomersNotEqualIfHaveDifferentIdentifier()
        {
            Customer firstCustomer = CreateCustomer(CustomerCommonTestValues.CustomerIdentifierString);
            Customer secondCustomer = CreateCustomer(CustomerCommonTestValues.SecondCustomerIdentifierString);

            Assert.AreNotEqual(firstCustomer, secondCustomer, "Two Customers with the same identifier should be equal.");
        }

        #endregion

        # region Tests - Expected Exceptions

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CannotPassInNullIdentifier()
        {
            new Customer(null);
        }

        # endregion

        # region Support Methods

        private Customer CreateCustomer(string customerIdentifierString)
        {
            CustomerIdentifier customerIdentifier = new CustomerIdentifier(customerIdentifierString);

            return new Customer(customerIdentifier);
        }

        # endregion
    }
}
